package com.hxm.meizi.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

import com.blankj.utilcode.utils.NetworkUtils;
import com.blankj.utilcode.utils.ToastUtils;

/**
 * Created by Hxm on 2017/2/22.
 * 监听网络状态
 */

public class NetStatusReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        switch (action) {
//            case WifiManager.WIFI_STATE_CHANGED_ACTION:
//                int wifiState=intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,0);
//                if (wifiState==WifiManager.WIFI_STATE_DISABLED){
//                    ToastUtils.showShortToast("Wifi连接断开");
//                }
//                if (wifiState==WifiManager.WIFI_STATE_ENABLED){
//                    ToastUtils.showShortToast("Wifi已连接");
//                }
//                break;
//            case WifiManager.NETWORK_STATE_CHANGED_ACTION:
//                if (NetworkUtils.isWifiAvailable()){
//                    ToastUtils.showShortToast("Wifi可用");
//                }else {
//                    ToastUtils.showShortToast("Wifi不可用");
//                }
//                break;
            case ConnectivityManager.CONNECTIVITY_ACTION:
                if (!NetworkUtils.isConnected()) {
                    ToastUtils.showShortToast("网络未连接");
                }
                break;
        }
    }
}
